<template>
  <div class="content">
    <span class="afterCantact">新增联系人</span>
    <el-form :model="ruleForm" label-width="100px">
      <el-form-item label="联系人" required>
        <el-input v-model="ruleForm.contact_name"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-select v-model="ruleForm.contact_sex" placeholder="请选择">
          <el-option label="男" value="1"></el-option>
          <el-option label="女" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="职位">
        <el-select v-model="ruleForm.position" placeholder="请选择">
          <el-option label="老板" value="1"></el-option>
          <el-option label="董事长" value="2"></el-option>
          <el-option label="总经理" value="3"></el-option>
          <el-option label="负责人" value="4"></el-option>
          <el-option label="业务员" value="5"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码" required>
        <el-input v-model="ruleForm.contact_phone"></el-input>
      </el-form-item>
      <el-form-item label="微信">
        <el-input v-model="ruleForm.contact_wechat"></el-input>
      </el-form-item>
      <el-form-item label="QQ">
        <el-input v-model="ruleForm.contact_qq"></el-input>
      </el-form-item>
      <el-form-item label="电子邮箱">
        <el-input v-model="ruleForm.contact_email"></el-input>
      </el-form-item>

      <el-form-item label="生日">
        <el-date-picker
          placeholder="选择日期"
          v-model="ruleForm.contact_birthday"
          style="width: 100%"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="备注">
        <el-input type="textarea" v-model="ruleForm.contact_remark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">保存</el-button>
        <el-button @click="resetForm">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { addContactAxios } from "../../http/apis/afterSaleApi";
export default {
  name: "afterCantact",
  data() {
    return {
      ruleForm: {
        contact_name: "",
        contact_sex: "",
        position: "",
        contact_phone: "",
        contact_wechat: "",
        contact_qq: "",
        contact_email: "",
        contact_birthday: "",
        contact_remark: "",
      },
      info: "",
    };
  },
  methods: {
    submitForm() {
      console.log(this.ruleForm, this.$route.query.info.customer_Id);
      addContactAxios(this.ruleForm, this.$route.query.info.customer_Id)
        .then((res) => {
          console.log("请求成功", res.data);
          this.$router.push({
            path: "/afterSale/addAfterSale",
            query: { editInfo: this.info },
          });
        })
        .catch((err) => {
          console.log("请求错误", err);
        });
    },
    resetForm() {
      this.$router.push({
        path: "/afterSale/addAfterSale",
        query: { editInfo: this.info },
      });
    },
  },
  created() {
    this.info = this.$route.query.info;
  },
};
</script>

<style lang="scss" scoped>
.el-form {
  width: 500px;
  margin: 0 auto;
}
.afterCantact {
  padding: 10px;
}
.el-input {
  width: 200px;
}
.el-form-item {
  width: 500px;
}
</style>